/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 - 2008 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.form.editor.gui.view.settings.panel;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.DocumentListener;

import com.genia.toolbox.basics.editor.gui.panel.AbstractPanel;
import com.genia.toolbox.form.editor.gui.FormEditorGUI;
import com.genia.toolbox.form.editor.message.Messages;

/**
 * The basic form settings panel.
 */
@SuppressWarnings("serial")
public abstract class AbstractFormSettingsPanel
    extends AbstractPanel<FormEditorGUI>
    implements DocumentListener
{

  /**
   * The document name label.
   */
  private JLabel labelDocumentName = null;

  /**
   * The document name textfield.
   */
  private JTextField textDocumentName = null;

  /**
   * The document type label.
   */
  private JLabel labelDocumentType = null;

  /**
   * The document type textfield.
   */
  private JTextField textDocumentType = null;

  /**
   * The key label.
   */
  private JLabel labelKey = null;

  /**
   * The key textfield.
   */
  private JTextField textKey = null;



  /**
   * Constructor.
   * 
   * @param gui
   *          The gui.
   */
  public AbstractFormSettingsPanel(FormEditorGUI gui)
  {
    super(gui);

    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    this.setLayout(layout);

    constraints.gridx = 1;
    constraints.gridy = 1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.insets = new Insets(5, 5, 5, 5);
    this.add(this.createMainPanel(), constraints);
  }



  /**
   * Create the main panel.
   * 
   * @return the main panel.
   */
  public JPanel createMainPanel()
  {
    JPanel panel = new JPanel();

    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    panel.setLayout(layout);

    panel.setBorder(BorderFactory.createTitledBorder(this.getGui().getController().notifyTranslation(Messages.DOCUMENT_SETTINGS_PANEL_FORM_TITLE)));

    this.labelDocumentName = new JLabel(this.getGui().getController().notifyTranslation(Messages.DOCUMENT_SETTINGS_PANEL_LABEL_NAME));
    constraints.gridx = 1;
    constraints.gridy = 1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.NORTH;
    constraints.insets = new Insets(5, 5, 5, 5);
    panel.add(this.labelDocumentName, constraints);

    this.textDocumentName = new JTextField();
    this.textDocumentName.getDocument().addDocumentListener(this);
    constraints.gridx = 2;
    constraints.gridy = 1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.NORTH;
    constraints.insets = new Insets(5, 0, 5, 5);
    panel.add(this.textDocumentName, constraints);

    this.labelDocumentType = new JLabel(this.getGui().getController().notifyTranslation(Messages.DOCUMENT_SETTINGS_PANEL_LABEL_TYPE));
    constraints.gridx = 1;
    constraints.gridy = 2;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.NORTH;
    constraints.insets = new Insets(0, 5, 5, 5);
    panel.add(this.labelDocumentType, constraints);

    this.textDocumentType = new JTextField();
    this.textDocumentType.setEditable(false);
    constraints.gridx = 2;
    constraints.gridy = 2;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.NORTH;
    constraints.insets = new Insets(0, 0, 5, 5);
    panel.add(this.textDocumentType, constraints);

    this.labelKey = new JLabel(this.getGui().getController().notifyTranslation(Messages.DOCUMENT_SETTINGS_PANEL_LABEL_KEY));
    constraints.gridx = 1;
    constraints.gridy = 3;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.NONE;
    constraints.anchor = GridBagConstraints.NORTH;
    constraints.insets = new Insets(0, 5, 5, 5);
    panel.add(this.labelKey, constraints);

    this.textKey = new JTextField();
    this.textKey.setEditable(true);
    this.textKey.getDocument().addDocumentListener(this);
    constraints.gridx = 2;
    constraints.gridy = 3;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 1;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.NORTH;
    constraints.insets = new Insets(0, 0, 5, 5);
    panel.add(this.textKey, constraints);

    constraints.gridx = 1;
    constraints.gridy = 4;
    constraints.gridwidth = 2;
    constraints.gridheight = 1;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.fill = GridBagConstraints.NONE;
    constraints.insets = new Insets(0, 0, 5, 5);
    panel.add(new JLabel(), constraints);

    return panel;
  }



  /**
   * Get the name text field.
   * 
   * @return the name text field.
   */
  public JTextField getNameTextField()
  {
    return this.textDocumentName;
  }



  /**
   * Get the name label.
   * 
   * @return the name label.
   */
  public JLabel getNameLabel()
  {
    return this.labelDocumentName;
  }



  /**
   * Get the type text field.
   * 
   * @return the type text field.
   */
  public JTextField getTypeTextField()
  {
    return this.textDocumentType;
  }



  /**
   * Get the type label.
   * 
   * @return the type label.
   */
  public JLabel getTypeLabel()
  {
    return this.labelDocumentType;
  }



  /**
   * Get the key text field.
   * 
   * @return the key text field.
   */
  public JTextField getKeyTextField()
  {
    return this.textKey;
  }



  /**
   * Get the key label.
   * 
   * @return the key label.
   */
  public JLabel getKeyLabel()
  {
    return this.labelKey;
  }

}
